<?php

namespace Home\Controller;

use Think\Controller;

/**
 * 外包客服外呼中心
 */
class AntiUserController extends CommnController
{

    public function __construct()
    {
        parent::__construct();
    }


    /**
     * 显示认证信息
     */
    public function show_verify()
    {
        $vid = I('vid');
        $field = 'taobao_verify,credit_verify,shebao_verify,jd_verify,mobile_verify,contact_verify,zhima_verify,work_cert';
        $v = M('user', '', 'USER')->where(['vid' => $vid])->field($field)->find();

        $data = array();
        if ($v['taobao_verify'] == 1) {
            $data[] = '淘宝未认证';
        }

        if ($v['credit_verify'] == 1) {

            $data[] = '信用卡未认证';
        }
        if ($v['shebao_verify'] == 1) {

            $data[] = '社保未认证';
        }
        if ($v['jd_verify'] == 1) {

            $data[] = '京东未认证';
        }
        if ($v['mobile_verify'] == 1) {

            $data[] = '运营商未认证';
        }
        if ($v['contact_verify'] == 0) {

            $data[] = '联系人未认证';
        }
        if ($v['zhima_verify'] == 0) {
            $data[] = '芝麻未认证';
        }
        if ($v['work_cert'] == 1) {

            $data[] = '工作未认证';
        }
        $this->assign(array(
            'data' => $data,
        ));
        $this->display();
        die;
    }

    /**
     * 添加快速回复标签
     */
    public function Quick_answer()
    {
        if (empty($_POST)) {
            $vid = I('get.vid');
            $url_type = I('get.url_type');
            $data = M('kefu_quick_answer', '', 'KEFU')->where(['type' => '1'])->field('title,id')->select();
            $this->assign(array(
                'data' => $data,
                'vid' => $vid,
                'url_type' => $url_type
            ));
            $this->display();
            die;
        }
        $title = I('title');
        $arr = array('title' => $title, 'ctime' => time(), 'kf_id' => $_SESSION['id'], 'type' => 1);
        $add = M('kefu_quick_answer', '', 'KEFU')->add($arr);
        if ($add) {
            add_log('添加快速回复' . $add);
            $this->ajax('1001', '添加成功');
            die;
        }
        $this->ajax('1002', '添加失败');
        die;
    }

    /**
     * 回复记录
     */
    public function Remarks()
    {
        if (empty($_POST)) {
            $vid = I('get.vid');
            $url_type = I('get.url_type');
            $this->assign(array(
                'vid' => $vid,
                'url_type' => $url_type
            ));
            $this->display();
            die;
        }
    }

    /**
     * 提交审核
     */
    public function commit_check()
    {
        $vid = I('vid');
        $arr = array('status' => 2, 'commit_time' => time());
        $update = M('user_artificial_check', '', 'KEFU')->where(['vid' => $vid])->save($arr);
        if ($update) {
            $this->ajax('1001', '提交成功');
            die;
        }
        $this->ajax('1002', '提交失败');
        die;
    }


    /**
     * 回复记录
     */
    public function outbound_result()
    {
        $vid = I('vid');
        $type1 = I('type1');
        $content = I('content');
        $quick_status = I('quick_status');
        $arr = array('admin_name' => $_SESSION['name'], 'content' => $content, 'ctime' => time(), 'vid' => $vid);
        $this->page = I('page');
        $add = M('tmp_user_mark', '', 'KEFU')->add($arr);
        if ($add) {
            $check = M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->field('status')->find();
            if ($check['status'] != 4 && $check['status'] != 5) {
                $arr = array('status' => 2, 'commit_time' => time(),'fk_status'=>0);
                M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->save($arr);
                M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->setfield('status', 2);
                add_log('对用户' . $vid . '外呼备注ID' . $add);
            }
            $this->ajax('1001', '备注成功');
            die;
        }
        $this->ajax('1002', '备注失败');
        die;
    }

    /**
     *提交记录
     */
    public function outbound_result_no()
    {
        $vid = I('vid');
        $type1 = I('type1');
        $content = I('content');
        $quick_status = I('quick_status');
        $arr = array('admin_name' => $_SESSION['name'], 'content' => $content, 'ctime' => time(), 'vid' => $vid);
        $this->page = I('page');
        $add = M('tmp_user_mark', '', 'KEFU')->add($arr);
        if ($add) {

            add_log('对用户' . $vid . '外呼备注ID' . $add);
            $this->ajax('1001', '备注成功');
            die;
        }
        $this->ajax('1002', '备注失败');
        die;
    }


    /**
     * 回复记录
     */
    public function outbound_result_1()
    {
        $vid = I('vid');
        $type1 = I('type1');
        $content = I('content');
        $quick_status = I('quick_status');
        $arr = array('admin_name' => $_SESSION['name'], 'content' => $content, 'ctime' => time(), 'vid' => $vid, 'type' => '1');
        $this->page = I('page');
        $add = M('user_outbound_message', '', 'KEFU')->add($arr);
        if ($add) {
            $arr = array('status' => 2, 'commit_time' => time());
            M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->save($arr);
            M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->setfield('status', 2);
            add_log('对用户' . $vid . '外呼备注ID' . $add);
            $this->ajax('1001', '备注成功');
            die;
        }
        $this->ajax('1002', '备注失败');
        die;

    }


    /**
     *  未通过审核列表
     */
    public function refuse_list()
    {
        $search = I('get.user');
        $where['a.mobile|a.truename'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('eq', '6');
        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->field('a.vid')->join('join dxd_kefu.admin c on b.out_kf_id=c.id')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.truename as name,a.mobile,a.sex,b.check_time,a.vid,c.name as admin_name';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->join('join dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->LIMIT($page->listfirst, $page->listRows)->order('b.check_time desc')->field($field)->select();

        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');
            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['check_time'] != 0) {
                $user[$k]['check_time'] = date('Y-m-d H:i', $v['check_time']);
            } else {
                $user[$k]['check_time'] = '-';
            }
        }


        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');


        $this->display();
    }

    /**
     *  未通过审核列表
     */
    public function refuse_list_1()
    {
        $search = I('get.user');
        $where['a.mobile|a.name'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('eq', '6');

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_fk.anti_cheat a on b.vid=a.vid')->where($where)->distinct('a.vid')->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.name,a.mobile,a.sex,a.logic_score,b.check_time,a.vid,c.name as admin_name';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_fk.anti_cheat a on b.vid=a.vid')->join('join dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->distinct('a.vid')->LIMIT($page->listfirst, $page->listRows)->order('b.check_time desc')->field($field)->select();

        foreach ($user as $k => $v) {
            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['check_time'] != 0) {
                $user[$k]['check_time'] = date('Y-m-d H:i', $v['commit_time']);
            } else {
                $user[$k]['check_time'] = '-';
            }
        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');


        $this->display();
    }

    /**
     *  通过审核列表
     */
    public function pass_list()
    {
        $search = I('get.user');
        $where['a.mobile|a.truename'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('eq', '5');

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.truename as name,a.mobile,a.sex,b.check_time,a.vid,c.name as admin_name';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->join('join dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->LIMIT($page->listfirst, $page->listRows)->order('b.check_time desc')->field($field)->select();

        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');

            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['check_time'] != 0) {
                $user[$k]['check_time'] = date('Y-m-d H:i', $v['check_time']);
            } else {
                $user[$k]['check_time'] = '-';
            }


        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');


        $this->display();
    }
    /**
     *  通过审核列表
     */
    public function pass_list_1()
    {
        $search = I('get.user');
        $where['a.mobile|a.truename'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('eq', '5');

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.truename as name,a.mobile,a.sex,b.check_time,a.vid,c.name as admin_name';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->join('join dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->LIMIT($page->listfirst, $page->listRows)->order('b.check_time desc')->field($field)->select();

        foreach ($user as $k => $v) {


            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['check_time'] != 0) {
                $user[$k]['check_time'] = date('Y-m-d H:i', $v['commit_time']);
            } else {
                $user[$k]['check_time'] = '-';
            }


        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');


        $this->display();
    }


    /**
     * 待审核审核列表
     */
    public function wait_pass_list()
    {
        $url_type = I('get.type');//1 风控未通过用户列表 2 无机型注册未认证 3 通过未借款  4 有机型注册未认证
        $this->url_type_status = I('get.type_status');//0 全部 1没沟通 2 沟通过 3 已经解决 4 去认证  用户列表沟通状态
        $page_first = I('get.page_first');
        $search = I('get.user');
        $this->rid = I('rid');
        $this->roles = role(I('rid'));
        $this->page = I('page', 0);
        $this->user_content = $search;
        $url_type_status = $this->url_type_status;

        $where['a.mobile|a.truename'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('in', array('2', '3'));
        if ($_SESSION['role_id'] != '3' && $_SESSION['role_id'] != '11' && $_SESSION['role_id'] != '13') {
            $where['b.out_kf_id'] = array('eq', $_SESSION['id']);
        }

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->distinct('a.vid')->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.truename as name,a.mobile,a.sex,b.status,b.commit_time,a.vid';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->LIMIT($page->listfirst, $page->listRows)->order('b.commit_time desc')->field($field)->select();

        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');


            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['commit_time'] != 0) {
                $user[$k]['commit_time'] = date('Y-m-d H:i', $v['commit_time']);
            } else {
                $user[$k]['commit_time'] = '-';
            }

            if ($v['status'] == '2') {
                $user[$k]['status'] = '待接收';
                $user[$k]['check_status'] = '1';

            } elseif ($v['status'] == '3') {
                $user[$k]['status'] = '审核中';
                $user[$k]['check_status'] = '2';
            }

        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');

        $this->display();
    }

//    /**
//     * 待审核审核列表
//     */
//    public function fk_check_result()
//    {
//
//        $vid = I('vid');
//        $status = I('status');
//
//        if ($status == '2') {//驳回
//            $arr = array('status' => 4, 'check_time' => time());
//            M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->save($arr);
//            M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->setfield('status', 3);
//            $this->ajax('1001', '驳回成功');
//            die;
//        }
//
//        $id = M('user_examine', '', 'RISK')->where(['vid' => $vid, 'status' => 2])->getfield('id');
////        $this->ajax('1001',$id.'--'.$vid);die;
//
//        if (!empty($id)) {
//            $post_data = array(
//                'vid' => $vid,
//                'id' => $id,
//                'status' => $status
//            );
//            $ret = $this->send_post('https://adm.56gxxj.com/External/external_risk_check', $post_data);
//            $json = json_decode($ret);
//            if ($json->code == '1001') {
//                if ($status == '0') {//通过
//                    $arr = array('status' => 5, 'check_time' => time());
//                    M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->save($arr);
//                    M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->setfield('status', 4);
//                } else if ($status == '1') {
//                    $arr = array('status' => 6, 'check_time' => time());
//                    M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->save($arr);
//                    M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->setfield('status', 5);
//                }
//
//            }
//            $this->ajax($json->code, $json->result);
//            die;
//        }
//        $this->ajax('1002', '用户有误');
//        die;
////        $this->ajax('1001',$id.'--'.$vid);die;
//
//    }

    /**
     * 待审核审核列表
     */
    public function fk_check()
    {
        $url_type = I('get.type');//1 风控未通过用户列表 2 无机型注册未认证 3 通过未借款  4 有机型注册未认证
        $this->url_type_status = I('get.type_status');//0 全部 1没沟通 2 沟通过 3 已经解决 4 去认证  用户列表沟通状态
        $page_first = I('get.page_first');
        $search = I('get.user');
        $this->rid = I('rid');
        $this->roles = role(I('rid'));
        $this->page = I('page', 0);
        $this->user_content = $search;
        $url_type_status = $this->url_type_status;

        $where['a.mobile|a.truename'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('in', array('2', '3'));
        if ($_SESSION['role_id'] != '3' && $_SESSION['role_id'] != '11' && $_SESSION['role_id'] != '13') {
            $where['b.out_kf_id'] = array('eq', $_SESSION['id']);
        }

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->distinct('a.vid')->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.truename as name,a.mobile,a.sex,b.status,b.commit_time,a.vid';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->LIMIT($page->listfirst, $page->listRows)->order('b.commit_time desc')->field($field)->select();

        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');


            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['commit_time'] != 0) {
                $user[$k]['commit_time'] = date('Y-m-d H:i', $v['commit_time']);
            } else {
                $user[$k]['commit_time'] = '-';
            }

            if ($v['status'] == '2') {
                $user[$k]['status'] = '待接收';
                $user[$k]['check_status'] = '1';

            } elseif ($v['status'] == '3') {
                $user[$k]['status'] = '审核中';
                $user[$k]['check_status'] = '2';
            }

        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');

        $this->display();
    }

    /**
     * 待审核审核列表
     */
    public function wait_pass_list_1()
    {
        $url_type = I('get.type');//1 风控未通过用户列表 2 无机型注册未认证 3 通过未借款  4 有机型注册未认证
        $this->url_type_status = I('get.type_status');//0 全部 1没沟通 2 沟通过 3 已经解决 4 去认证  用户列表沟通状态
        $page_first = I('get.page_first');
        $search = I('get.user');
        $this->rid = I('rid');
        $this->roles = role(I('rid'));
        $this->page = I('page', 0);
        $this->user_content = $search;
        $url_type_status = $this->url_type_status;

        $where['a.mobile|a.name'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('in', array('2', '3'));
        if ($_SESSION['role_id'] == '10') {
            $where['b.out_kf_id'] = array('eq', $_SESSION['id']);
        }

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_fk.anti_cheat a on b.vid=a.vid')->where($where)->distinct('a.vid')->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.name,a.mobile,a.sex,b.status,b.commit_time,a.vid';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_fk.anti_cheat a on b.vid=a.vid')->where($where)->distinct('a.vid')->LIMIT($page->listfirst, $page->listRows)->order('b.commit_time desc')->field($field)->select();

        foreach ($user as $k => $v) {
            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
            if ($v['commit_time'] != 0) {
                $user[$k]['commit_time'] = date('Y-m-d H:i', $v['commit_time']);
            } else {
                $user[$k]['commit_time'] = '-';
            }

            if ($v['status'] == '2') {
                $user[$k]['status'] = '待接收';
                $user[$k]['check_status'] = '1';

            } elseif ($v['status'] == '3') {
                $user[$k]['status'] = '审核中';
                $user[$k]['check_status'] = '2';
            }
        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');
        $this->display();
    }

    /**
     * 用户详情
     */
    public function user_info()
    {
        $page11 = I('page11', 0);
        $page_first = I('get.page_first11', 0);
        $vid = I('get.vid');
        //修改调查状态
//        M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->setfield('status', 7);
        $field='vid,mobile,sex,ctime,address,residence_time,id_card,shebao_verify,work_verify,taobao_verify,jd_verify,credit_verify,edu_verify,alipay_verify';
        $user = M('user', '', 'USER')->where(['vid' => $vid])->field($field)->find();

        //用户各种认证
        // 社保认证 1：未认证 2：认证中 3认证成功，4.认证失败
        switch ($user['shebao_verify']){
            case 1: $user['shebao_verify']='未认证';break;
            case 2: $user['shebao_verify']='认证中';break;
            case 3: $user['shebao_verify']='认证成功';break;
            case 4: $user['shebao_verify']='认证失败';break;
        }

        //京东认证1：未认证 2：认证中 3认证成功，4.认证失败
        switch ($user['jd_verify']){
            case 1: $user['jd_verify']='未认证';break;
            case 2: $user['jd_verify']='认证中';break;
            case 3: $user['jd_verify']='认证成功';break;
            case 4: $user['jd_verify']='认证失败';break;
        }

        //工作认证 1认证2未认证
        switch ($user['work_verify']){
            case 1: $user['work_verify']='认证';break;
            case 2: $user['work_verify']='未认证';break;
            case 0: $user['work_verify']='未认证';break;
        }

        //淘宝认证 1：未认证 2：认证中 3认证成功，4.认证失败
        switch ($user['taobao_verify']){
            case 1: $user['taobao_verify']='未认证';break;
            case 2: $user['taobao_verify']='认证中';break;
            case 3: $user['taobao_verify']='认证成功';break;
            case 4: $user['taobao_verify']='认证失败';break;
        }

        //信用卡认证 1：未认证 2：认证中 3认证成功，4.认证失败
        switch ($user['credit_verify']){
            case 1: $user['credit_verify']='未认证';break;
            case 2: $user['credit_verify']='认证中';break;
            case 3: $user['credit_verify']='认证成功';break;
            case 4: $user['credit_verify']='认证失败';break;
        }
        //学历认证1未认证2认证中3已认证
        switch ($user['edu_verify']){
            case 1: $user['edu_verify']='未认证';break;
            case 2: $user['edu_verify']='认证中';break;
            case 3: $user['edu_verify']='认证成功';break;
            case 4: $user['edu_verify']='认证失败';break;
        }
        //支付宝认证1未认证，2认证中，3已认证，4认证失败
        switch ($user['alipay_verify']){
            case 1: $user['alipay_verify']='未认证';break;
            case 2: $user['alipay_verify']='认证中';break;
            case 3: $user['alipay_verify']='认证成功';break;
            case 4: $user['alipay_verify']='认证失败';break;
        }
        //驳回
        $refuse = M('tmp_user', '', 'KEFU')->where(['vid' => $vid])->getfield('status');
        $refuse1 = M('anti_check_user', '', 'KEFU')->where(['vid' => $vid])->getfield('status');
        if ($refuse == 3 || $refuse == 4 || $refuse == 5 || $refuse1 == 8) {
            $refuse_content = M('temp_log', '', 'KEFU_FK')->where(['vid' => $vid])->field('content')->order('id desc')->limit(1)->find();
            $user['refuse_content'] = $refuse_content['content'];
            $user['refuse_status'] = '3';
        } else {
            $user['refuse_status'] = '0';
        }

        $sub = M('temp_check_tag', '', 'KEFU_FK')->where(['vid' => $vid])->field('max(ctime) as t_time')->find();
        $tag = M('temp_check_tag', '', 'KEFU_FK')->where(['vid' => $vid, 'ctime' => $sub['t_time']])->getField('tag', true);
        $tags = implode('-', $tag);

        $first = substr($user['id_card'], 0, 3);
        $end = substr($user['id_card'], strlen($user['id_card']) - 9, strlen($user['id_card']));
        $user['id_card'] = $first . '******' . $end;

        $user_pic = M('user_idcard_img', '', 'USER')->where(['vid' => $user['vid']])->field('photo,photo1,photo2,front,behind')->find();
        $user['ctime'] = date('Y-m-d H:i', $user['ctime']);
        $user_contact = M('user_contact', '', 'USER')->where(['vid' => $vid])->field('relative_name,relative_mobile,r_type,other_name,other_mobile,f_type')->find();
        $w = [];
        $w['mymobile'] = array('eq', $user['mobile']);
        $w['call_other_number'] = array('eq', $user_contact['relative_mobile']);

        $contact_sum = M('mobile_callrecord_s', '', 'KF_USER_TX')->where($w)->count();
        $contact_sum2 = M('mobile_callrecord_s', '', 'KF_USER_TX')->where(['mymobile' => $user['mobile'], 'call_other_number' => $user_contact['other_mobile']])->count();
        $user_contact['contact_sum'] = $contact_sum;
        $user_contact['contact_sum2'] = $contact_sum2;

        $user['score'] = M('user_good_bad', '', 'USER')->where(['vid' => $vid])->getfield('logic_level');

//        $user['score'] = M('anti_cheat', '', 'KEFU_FK')->where(['vid' => $vid])->getfield('logic_score');

        //通讯录列表
        $field = "b.call_other_number,count(b.call_other_number) as num, a.mobile";
        $tol = M('user_mobilebook', '', 'KF_USER_TX')->where(['vid' => $vid])->count();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();

//       $user_tx = M('user_mobilebook', '', 'KF_USER_TX')->join('a left join zhengxin.mobile_callrecord_s b on a.mobile=b.call_other_number')->where(['a.vid' => $vid,'b.mymobile'=>$user['mobile']])->field($field)->LIMIT($page->listfirst, $page->listRows)->group('b.call_other_number')->order('num desc')->select();
        $user_tx = M('user_mobilebook', '', 'KF_USER_TX')->query('SELECT a.name , a.mobile as call_other_number ,IFNULL(b.num,0) as num
                                                              from user_mobilebook a 
                                                              left join (SELECT call_other_number,COUNT(call_other_number) as num 
                                                                          FROM mobile_callrecord_s 
                                                                          WHERE mymobile=\'' . $user['mobile'] . '\' 
                                                                          GROUP BY call_other_number) b 
                                                                          on a.mobile=b.call_other_number 
                                                                          WHERE  a.vid=\'' . $user['vid'] . '\'
                                                                          ORDER BY num desc LIMIT ' . $page->listfirst . ',' . $page->listRows);


        //反馈详情
        $feedback = M('tmp_user_mark', '', 'KEFU')->where(['vid' => $vid])->field('content')->limit(1)->find();
        if (!empty($feedback)) {
            $user['feedback_status'] = '1';//已经备注过
        } else {
            $user['feedback_status'] = '0';//没有备注过
        }
        //用户认证
        $this->assign(array(
            'user' => $user,
            'user_tx' => $user_tx,
            'user_pic' => $user_pic,
            'user_contact' => $user_contact,
            'fpage' => $fpage,
            'tol' => $tol,
            'pages' => $page->listfirst,
            'vid' => $vid,
            'page11' => $page11,
            'page_first11' => $page_first,
            'role' => $_SESSION['role_id'],
            'tag'=>$tags
        ));
        $this->display();
    }

    /**
     * 反欺诈用户列表  待查
     */
    public function anti_user_list()
    {
//        $url_type = I('get.type');//1 风控未通过用户列表 2 无机型注册未认证 3 通过未借款  4 有机型注册未认证
        $this->url_type_status = I('get.type_status');//0 全部 1没沟通 2 沟通过 3 已经解决 4 去认证  用户列表沟通状态
        $page_first = I('get.page_first');
        $search = I('get.user');
        $this->rid = I('rid');
        $this->roles = role(I('rid'));
        $this->page = I('page', 0);
        $this->user_content = $search;
        if ($_SESSION['role_id'] != '3' && $_SESSION['role_id'] != '11' && $_SESSION['role_id'] != '13') {
            $where['b.out_kf_id'] = array('eq', $_SESSION['id']);
            $w['out_kf_id'] = array('eq', $_SESSION['id']);
        }

        $where['a.mobile|a.truename'] = array('like', '%' . $search . '%');
        //普通客服只能看见分配给自己的用户


        $where['b.status'] = array('eq', 2);
        $w['status'] = array('eq', 2);
        $tol = M('user_artificial_check', '', 'KEFU')->where($where)->count();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }
        $field = 'a.truename as name,a.mobile,a.sex,b.status,a.cert_time,a.vid,c.name as admin_name,d.name as ch_name ';
        $user = M('user_artificial_check', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->join('left join dxd_cpa.channel_merchant d on d.channel_num=a.channel')->where($where)->LIMIT($page->listfirst, $page->listRows)->field($field)->select();
        foreach ($user as $k => $v){
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');

            if ($v['cert_time'] != 0) {
                $user[$k]['cert_time'] = date('Y-m-d H:i', $v['cert_time']);
            } else {
                $user[$k]['cert_time'] = '-';
            }

            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }

            if ($v['status'] == 0 || $v['status']==12) {
                $user[$k]['status'] = '未开始';
            } elseif ($v['status'] == 1) {
                $user[$k]['status'] = '已经调查';
            } else if ($v['status'] == 4) {
                $user[$k]['status'] = '审核驳回';
            } else if ($v['status'] == 7) {
                $user[$k]['status'] = '正在调查';
            } else if ($v['status'] == 8) {
                $user[$k]['status'] = '驳回';
            }
        }

        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol,
            'rid' => $this->rid,
            'admin' => $_SESSION['role_id']
        ));
        $this->page = I('page');
        $this->display();
    }

    /**
     * 反欺诈用户列表  待查
     */
    public function anti_user_list_1()
    {
        $url_type = I('get.type');//1 风控未通过用户列表 2 无机型注册未认证 3 通过未借款  4 有机型注册未认证
        $this->url_type_status = I('get.type_status');//0 全部 1没沟通 2 沟通过 3 已经解决 4 去认证  用户列表沟通状态
        $page_first = I('get.page_first');
        $search = I('get.user');
        $this->rid = I('rid');
        $this->roles = role(I('rid'));
        $this->page = I('page', 0);
        $this->user_content = $search;
        if ($_SESSION['role_id'] == '10') {
            $where['b.out_kf_id'] = array('eq', $_SESSION['id']);
        }
        $where['a.mobile|a.name'] = array('like', '%' . $search . '%');
        $where['b.status'] = array('in', array('0', '1', '4'));

        $sum = M('anti_check_user', '', 'KEFU')->join('b join dxd_fk.anti_cheat a on b.vid=a.vid')->where($where)->distinct('a.vid')->field('a.vid')->select();
        $tol = count($sum);
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }

        $field = 'a.name,a.mobile,a.sex,b.status,a.logic_score,cert_time,a.vid';
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_fk.anti_cheat a on b.vid=a.vid')->where($where)->distinct('a.vid')->LIMIT($page->listfirst, $page->listRows)->order('a.ctime desc')->field($field)->select();

//        var_dump($user);die;

        foreach ($user as $k => $v) {

            if ($v['cert_time'] != 0) {
                $user[$k]['cert_time'] = date('Y-m-d H:i', $v['cert_time']);
            } else {
                $user[$k]['cert_time'] = '-';
            }

            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }

            if ($v['status'] == 0 || $v['status'] == 1) {
                $user[$k]['status'] = '未开始';
            } else if ($v['status'] == 4) {
                $user[$k]['status'] = '审核驳回';
            }

        }

        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
//            'url_type' => $url_type,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));
        $this->page = I('page');
        $this->display();

    }

    /**
     * 编辑内容
     */
    public function edit_content_1()
    {
        if (empty($_POST)) {
            $id = I('get.id');
            $content = M('user_outbound_message', '', 'KEFU')->where(['id' => $id])->field('content,vid')->find();
            $this->assign(array(
                'content' => $content['content'],
                'id' => $id,
                'vid' => $content['vid']
            ));
            $this->display();
        } else {
            $id = I('id');
            $content = I('edit_content');

            $info = M('user_outbound_message', '', 'KEFU')->where(['id' => $id])->setfield('content', $content);
            if ($info) {
                add_log('修改外呼记录' . $id);
                $this->ajax('1001', '修改成功');
                die;
            }
            $this->ajax('1002', '修改失败');
            die;
        }
    }

    /**
     * 编辑内容
     */
    public function edit_content()
    {

        if (empty($_POST)) {
            $id = I('id');
            $content = M('tmp_user_mark', '', 'KEFU')->where(['id' => $id])->field('content,vid')->find();
            $this->assign(array(
                'content' => $content['content'],
                'id' => $id,
                'vid' => $content['vid']
            ));

//            var_dump($content);die;
            $this->display();
        } else {
            $id = I('id');
            $content = I('edit_content');
            $info = M('tmp_user_mark', '', 'KEFU')->where(['id' => $id])->setfield('content', $content);
            if ($info) {
                add_log('修改外呼记录' . $id);
                $this->ajax('1001', '修改成功');
                die;
            }
            $this->ajax('1002', '修改失败');
            die;
        }

    }


    /**
     * 详情
     */

    public function list_details()
    {
        $vid = I('get.vid');
        $data = M('tmp_user_mark', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where(['b.vid' => $vid])->field('b.id,b.admin_name,b.content,b.ctime,b.vid,a.truename,a.mobile')->select();

        foreach ($data as $k => $v) {
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }

//        $this->admin_name=$_SESSION['name'];
//        $this->id=$id;
        $url_type = I('url_type');
        $type_status = I('type_status');
        $this->page = I('page');
        $this->assign(array(
            'data' => $data,
            'vid' => $vid,
            'url_type' => $url_type,
            'type_status' => $type_status
        ));
        $this->display();
    }

    /**
     * 详情
     */

    public function list_details_1()
    {
        $vid = I('get.vid');
        $data = M('user_outbound_message', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where(['b.vid' => $vid])->field('b.id,b.admin_name,b.content,b.ctime,b.vid,a.truename,a.mobile')->select();

        foreach ($data as $k => $v) {
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
//        $this->admin_name=$_SESSION['name'];
//        $this->id=$id;
        $url_type = I('url_type');
        $type_status = I('type_status');
        $this->page = I('page');
        $this->assign(array(
            'data' => $data,
            'vid' => $vid,
            'url_type' => $url_type,
            'type_status' => $type_status
        ));

        $this->display();
    }

    /**
     * 发送post请求
     * @param string $url 请求地址
     * @param array $post_data post键值对数据
     * @return string
     */
    public function send_post($url, $post_data)
    {
        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间（单位:s）
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }


    /**
     * http请求
     * @param  string $url 请求地址
     * @param  boolean|string|array $params 请求数据
     * @param  integer $ispost 0/1，是否post
     * @param  array $header
     * @param  $verify 是否验证ssl
     * return string|boolean          出错时返回false
     */
    function http($url, $params, $ispost = 1, $header = [], $verify = false)
    {
        $httpInfo = array();
        $ch = curl_init();
        if (!empty($header)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        //忽略ssl证书
        if ($verify === true) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        } else {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        if ($ispost) {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            curl_setopt($ch, CURLOPT_URL, $url);
        } else {
            if (is_array($params)) {
                $params = http_build_query($params);
            }
            if ($params) {
                curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
            } else {
                curl_setopt($ch, CURLOPT_URL, $url);
            }
        }
        $response = curl_exec($ch);
        if ($response === FALSE) {
            trace("cURL Error: " . curl_errno($ch) . ',' . curl_error($ch), 'error');
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
            trace($httpInfo, 'error');
            return false;
        }
        curl_close($ch);
        return $response;
    }

    /**
     * 开始外呼
     */
    public function call()
    {
        $times = date('YmdHis', time());
        $phone = I('phone');
        $accountID = 'N00000017174';
        $APISecret = '1b4c7a40-d664-11e7-acd3-d9bc7f04577f';
        $number = $accountID . $APISecret . $times;
        $sig_s = md5($number);
        $sig = strtoupper($sig_s);
        $url = 'http://apis.7moor.com/v20160818/call/dialout/N00000017174?sig=' . $sig;
        $agent = M('admin', '', 'KEFU')->where(['id' => $_SESSION['id']])->getField('agent');
        $FromExten = substr($agent, 0, 4);
        $post_data = array('FromExten' => $FromExten, 'Exten' => $phone, 'ExtenType' => 'gateway');
        $post_data = json_encode($post_data);

        $str = 'N00000017174:' . $times;
        $baseStr = base64_encode($str);
        $header = array("Accept:application/json", "Content-Type:application/json;charset=utf-8", "Content-Length:" . strlen($post_data), "Authorization:" . $baseStr);
        $ret = $this->http($url, $post_data, 1, $header);
        $data = [];
        $data['ret'] = $ret;
        $data['url'] = $url;
        $data['header'] = $header;
        $data['post_data'] = $post_data;
        $this->ajax('1001', $data);
        die;
        if ($json->code == '1001') {
        }
        $this->ajax($json->code, $json->result);
        die;
//        账户编号：	N00000017174
//        帐号APISecret：	1b4c7a40-d664-11e7-acd3-d9bc7f04577f
//
//    PBX   	地址
//hz.ali.1.4	http://120.26.127.74

    }

    /**
     * opt请求数组数据
     * @param  [type] $url       url地址
     * @param  [type] $postData post的数据数组key=>value对,如果此项有数据自动转换为post请求
     * @param  [type] $headers  请求头信息为一维数组
     * @return [type]           返回网页内容
     */
    function send_request($conf)
    {
//    $conf = [
//        'url'      => '',
//        'postdata' => [], //有数据时自动转为post
//        'headers'  => [],
//        'post'     => false, //默认为false，true时当前请求强制转为post
//    ];
//    $conf = array_merge($conf, $opt);
        if (is_string($conf['headers'])) {
            $conf['headers'] = trim($conf['headers']);
            $conf['headers'] = preg_split('/\r?\n/', $conf['headers']);
        }

        if (!$conf['url']) {
            return '';
        }
        // var_dump($conf['postdata']);
        // var_dump($conf['headers']);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $conf['url']);
        if ($conf['postdata'] || $conf['post'] === true) {
            curl_setopt($ch, CURLOPT_POST, 1);
            $postdata = http_build_query($conf['postdata']);
            $conf['postdata'] && curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); //设置post数据
        } else {
            curl_setopt($ch, CURLOPT_POST, 0);
        }
        // var_dump($conf['postdata']);
        //curl_setopt($ch,CURLOPT_HEADER,1); //将头文件的信息作为数据流输出
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回内容不输出到浏览器
        // curl_setopt($ch, CURLOPT_REFERER, $conf['url']); //设置来源地址
        $conf['headers'] && curl_setopt($ch, CURLOPT_HTTPHEADER, $conf['headers']); //设置请求头
        $result = curl_exec($ch);
        //如果上面设置啦头信息到数据流可以用下面的方法取响应头中的信息
        //$weizhi = strpos($result, "\r\n\r\n");
        //请求头信息
        //$re_header = substr($result, 0, $weizhi);
        //返回的内容
        //$result = substr($result, $weizhi + 4);
        //preg_match_all('/Set-Cookie:stest=(.*)/i', $result, $cookie);
        //请求出错退出
        if ($error = curl_error($ch)) {
            die($error);
        }
        curl_close($ch);
        return $result;
    }

    public function copy_record()
    {
        $content = I('content');
        $type = I('type');
        switch ($type) {
            case 1:
                $from = '反欺诈通过审核列表';
                break;
            case 2:
                $from = '临时当天需还款列表';
                break;
            case 3:
                $from = '已还款逾期列表';
                break;
            case 4:
                $from = '未还款逾期列表';
                break;
            case 5:
                $from = '逾期已移交列表';
                break;
        }
        $arr = array('time' => date('Y-m-d H:i:s', time()), 'content' => $content, 'admin' => $_SESSION['name'], 'from' => $from);
        M('copy_data', '', 'KEFU')->add($arr);
    }

    //分配统计
    public function distribution_statistics()
    {
        // 99 70  67
        $where = [];
        $where['part_id'] = array('eq', 4);//风控客服
        $where['role_id'] = array('eq',15);//风控客服
        $admin = M('admin', '', 'KEFU')->where($where)->field('id,name')->select();
        $time=time();
        $s_time=strtotime(date('Y-m-d',$time));
        foreach ($admin as $k => $v) {
            //历史总调查数
            $where=[];
            $where['admin_name']=array('like','%'.$v['name'].'%');
            $survey_tol = M('tmp_user_mark', '', 'KEFU')->where($where)->count('DISTINCT vid');
            $admin[$k]['survey_tol'] = $survey_tol;
            //正在调查数
            $surveying = M('user_artificial_check', '', 'KEFU')->where(['out_kf_id' => $v['id'], 'status' => 2,'ready_time'=>array('gt',0)])->count();
            $admin[$k]['surveying'] = $surveying;
            //今日调查数
            $where['ctime']=array('between',array($s_time,$time));
            $survey_day = M('tmp_user_mark', '', 'KEFU')->where($where)->count('DISTINCT vid');
            $admin[$k]['survey_day'] = $survey_day;
           //未调查数
            $w = [];
            $w['status'] = array('eq', 2);
            $w['ready_time'] = array('eq',0);
            $w['out_kf_id'] = array('eq',$v['id']);
            $survey_no = M('user_artificial_check', '', 'KEFU')->where($w)->count();
            $admin[$k]['survey_no'] = $survey_no;
        }

        $this->assign(array(
            'admin' => $admin,
        ));
        $this->display();
    }

    //分配统计
    public function distribution_statistics1()
    {
        // 99 70  67
        $where = [];
        $where['part_id'] = array('eq', 4);//风控客服
        $where['role_id'] = array('eq',15);//风控客服
        $admin = M('admin', '', 'KEFU')->where($where)->field('id,name')->select();
        $time=time();
        $s_time=strtotime(date('Y-m-d',$time));
        foreach ($admin as $k => $v) {
            //历史总调查数
            $where=[];
            $where['admin_name']=array('like','%'.$v['name'].'%');
            $survey_tol = M('tmp_user_mark', '', 'KEFU')->where($where)->count('DISTINCT vid');
            $admin[$k]['survey_tol'] = $survey_tol;
            //正在调查数
            $surveying = M('anti_check_user', '', 'KEFU')->where(['out_kf_id' => $v['id'], 'status' => 7])->count();
            $admin[$k]['surveying'] = $surveying;

            //今日调查数
            $where['ctime']=array('between',array($s_time,$time));
            $survey_day = M('tmp_user_mark', '', 'KEFU')->where($where)->count('DISTINCT vid');
            $admin[$k]['survey_day'] = $survey_day;

            //未调查数
            $w = [];
            $w['status'] = array('in', array(0, 8,12));
            $w['out_kf_id'] = array('eq', $v['id']);
            $survey_no = M('anti_check_user', '', 'KEFU')->where($w)->count();
            $admin[$k]['survey_no'] = $survey_no;
        }
        $this->assign(array(
            'admin' => $admin,
        ));

        $this->display();


    }




    //预审分配统计
    public function font_check()
    {
        // 99 70  67
        $where = [];
        $where['part_id'] = array('eq', 1);//
        $where['status'] = array('eq',1);//
        $where['out_kf_id'] = array('eq',0);//
        $where['role_id'] = array('eq',2);//
        $admin = M('admin', '', 'KEFU')->where($where)->field('id,name')->select();
        foreach ($admin as $k => $v) {

//            //正在调查数
            $surveying = M('anti_check_user', '', 'KEFU')->where(['out_kf_id' => $v['id'], 'status' => 9])->count();
            $admin[$k]['wait_check'] = $surveying;
//            //未调查数
//            $w = [];
//            $w['status'] = array('in', array(0, 8));
//            $w['out_kf_id'] = array('eq', $v['id']);
//            $survey_no = M('anti_check_user', '', 'KEFU')->where($w)->count();
//            $admin[$k]['survey_no'] = $survey_no;
        }
        $this->assign(array(
            'admin' => $admin,
            'rid' => 104,
        ));

        $this->display();


    }


    //统计客服调查信息
    public function admin_user_list()
    {
        $id = I('id');
        $type = I('type', 1);//1 全部 ，2未调查 ，3已调查 4 今日调查  5 预审列表
        $search = I('user');
        $url_type_status = I('url_type_status');
        if(!empty($search)){
            $where['a.truename|a.mobile']=array('like','%'.$search.'%');
        }
        $field = 'a.truename as name,a.mobile,a.sex,b.status,a.cert_time,a.vid,c.name as admin_name ,a.ctime,b.commit_time';
        $admin=M('admin','','KEFU')->where(['id'=>$id])->getField('name');
        $row = '10';
        switch ($type){
            case 1:
                break;
            case 2:
                $where['b.status'] = array('in', array(0, 8,12));
                break;
            case 3:

                $where['b.status'] = array('in', array(2, 3, 4,5,6,12));
                break;
            case 4:
                $str=strtotime(date('Y-m-d',time()));
                $where['ctime']=array('egt',$str);
                $where['admin_name'] = array('like', '%'.$admin.'%');
                $tol = M('tmp_user_mark', '', 'KEFU')->where($where)->count('DISTINCT vid');
                $sub = M('tmp_user_mark', '', 'KEFU')->where($where)->group('vid')->field('vid')->select(false);
                $page = new PageController($tol, $row);
                $fpage = $page->fpage();
                if (!empty($page_first)) {
                    $page->listfirst = $this->page;
                }
                $user = M('anti_check_user', '', 'KEFU')->table('('.$sub.') d')->join('join dxd_kefu.anti_check_user b on b.vid=d.vid')->join('join dxd_user.user a on b.vid=a.vid')->join('dxd_kefu.admin c on b.out_kf_id=c.id')->order('b.ctime asc')->LIMIT($page->listfirst, $page->listRows)->field($field)->select();
                break;
            case 5:
                $row = '30';
                $where['b.status'] = array('eq',9);
                break;
        }

        if($type!=4){
        $where['b.out_kf_id'] = array('eq', $id);
        $tol = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->count();
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        if (!empty($page_first)) {
            $page->listfirst = $this->page;
        }
        $user = M('anti_check_user', '', 'KEFU')->join('b join dxd_user.user a on b.vid=a.vid')->join('dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->order('b.ctime asc')->LIMIT($page->listfirst, $page->listRows)->field($field)->select();
        }
        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');
            $user[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
            if ($v['cert_time'] != 0) {
                $user[$k]['cert_time'] = date('Y-m-d H:i', $v['cert_time']);
            } else {
                $user[$k]['cert_time'] = '-';
            }
            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }

            if ($v['status'] == 0) {
                $user[$k]['status'] = '未开始';
            } elseif ($v['status'] == 1) {
                $user[$k]['status'] = '重审';
            } elseif ($v['status'] == 2) {
                $user[$k]['status'] = '提交审核待接收';
            } elseif ($v['status'] == 3) {
                $user[$k]['status'] = '审核中 ';
            } else if ($v['status'] == 4) {
                $user[$k]['status'] = '审核驳回';
            } else if ($v['status'] == 5) {
                $user[$k]['status'] = '审核通过';
            } else if ($v['status'] == 6) {
                $user[$k]['status'] = '审核不通过';
            }else if ($v['status'] == 7) {
                $user[$k]['status'] = '正在调查';
            } else if ($v['status'] == 8) {
                $user[$k]['status'] = '驳回';
            }else if ($v['status'] == 9) {
                $user[$k]['status'] = '工作认证预审';
            }else if ($v['status'] == 10) {
                $user[$k]['status'] = '预审不通过';
            }else if ($v['status'] == 11) {
                $user[$k]['status'] = '预审通过';
            }else if ($v['status'] == 12) {
                $user[$k]['status'] = '重审';
            }
            //调查时间
            if(!empty($v['commit_time'])){
                $user[$k]['commit_time']=date('Y-m-d H:i',$v['commit_time']);
            }else{
                $user[$k]['commit_time']="---";
            }

        }
        $this->assign(array(
            'user' => $user,
            'fpage' => $fpage,
            'tol' => $tol,
            'id' => $id,
            'rid' => I('rid'),
            'type' => $type,
            'url_type_status' => $url_type_status,
        ));

        $this->display();
    }

    //修改紧急联系人
    public function edit_contact(){
        $vid=I('vid');
        $relative_name=I('relative_name');
        $relative_mobile=I('relative_mobile');
        $r_type=I('r_type');

        $other_name=I('other_name');
        $other_mobile=I('other_mobile');
        $f_type=I('f_type');

        $arr=array('relative_name'=>$relative_name,
            'relative_mobile'=>$relative_mobile,
            'r_type'=>$r_type,
            'other_name'=>$other_name,
            'other_mobile'=>$other_mobile,
            'f_type'=>$f_type);

      $update=  M('user_contact','','USER')->where(['vid'=>$vid])->save($arr);
       if($update){
           $this->ajax('1001','修改成功');
           die;
       }

        $this->ajax('1002','修改失败');
        die;
    }

    //预审统计



}